package x.mybatis.metadata;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 表元数据
 *
 * @author hanjuntao
 * @date 2025/5/8 0008
 */
public class TableMetadata {
    /**
     * 实体类
     */
    private Class<?> entityClass;

    /**
     * 表名
     */
    private String tableName;

    /**
     * 所有字段元数据
     */
    private List<ColumnMetadata> columns;

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public List<ColumnMetadata> getColumns() {
        return columns;
    }

    public void setColumns(List<ColumnMetadata> columns) {
        this.columns = columns;
    }

    public Class<?> getEntityClass() {
        return entityClass;
    }

    public void setEntityClass(Class<?> entityClass) {
        this.entityClass = entityClass;
    }

    @Override
    public String toString() {
        return "TableMetadata{" +
                "entityClass=" + entityClass +
                ", tableName='" + tableName + '\'' +
                ", columns=" + columns +
                '}';
    }

    /**
     * 获取字段元数据
     *
     * @return key: java实体字段名称, value: 字段元数据
     */
    public Map<String, ColumnMetadata> getPropertyMap() {
        return columns.stream().collect(Collectors.toMap(ColumnMetadata::getFieldName, v -> v));
    }
}
